Example #1
0
/**
 * Disables the unsupported eAccelerator caching method, replacing it with the
 * "file" caching method.
 *
 * @return  void
 *
 * @since   3.2
 */
function admin_postinstall_eaccelerator_action()
{
    $prev = new JConfig();
    $prev = JArrayHelper::fromObject($prev);
    $data = array('cacheHandler' => 'file');
    $data = array_merge($prev, $data);
    $config = new Registry('config');
    $config->loadArray($data);
    jimport('joomla.filesystem.path');
    jimport('joomla.filesystem.file');
    // Set the configuration file path.
    $file = JPATH_CONFIGURATION . '/configuration.php';
    // Get the new FTP credentials.
    $ftp = JClientHelper::getCredentials('ftp', true);
    // Attempt to make the file writeable if using FTP.
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) {
        JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'));
    }
    // Attempt to write the configuration file as a PHP class named JConfig.
    $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
    if (!JFile::write($file, $configuration)) {
        JFactory::getApplication()->enqueueMessage(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'), 'error');
        return;
    }
    // Attempt to make the file unwriteable if using FTP.
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) {
        JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'));
    }
}
 public function bind($array, $ignore = '')
 {
     // Search for the {readmore} tag and split the text up accordingly.
     if (isset($array['value']) && is_array($array['value'])) {
         $registry = new Registry();
         $registry->loadArray($array['value']);
         $array['value'] = (string) $registry;
     }
     //        if (isset($array['media']) && is_array($array['media']))
     //        {
     //            $registry = new Registry;
     //            $registry->loadArray($array['media']);
     //            $array['media'] = (string) $registry;
     //        }
     //
     //        if (isset($array['metadata']) && is_array($array['metadata']))
     //        {
     //            $registry = new Registry;
     //            $registry->loadArray($array['metadata']);
     //            $array['metadata'] = (string) $registry;
     //        }
     //
     //        // Bind the rules.
     //        if (isset($array['rules']) && is_array($array['rules']))
     //        {
     //            $rules = new JAccessRules($array['rules']);
     //            $this->setRules($rules);
     //        }
     return parent::bind($array, $ignore);
 }
Example #3
0
 /**
  * Overloaded bind function
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  An optional array or space separated list of properties
  *                          to ignore while binding.
  *
  * @return  mixed  Null if operation was satisfactory, otherwise returns an error string
  *
  * @see     JTable::bind()
  * @since   3.1
  */
 public function bind($array, $ignore = '')
 {
     if (isset($array['core_params']) && is_array($array['core_params'])) {
         $registry = new Registry();
         $registry->loadArray($array['core_params']);
         $array['core_params'] = (string) $registry;
     }
     if (isset($array['core_metadata']) && is_array($array['core_metadata'])) {
         $registry = new Registry();
         $registry->loadArray($array['core_metadata']);
         $array['core_metadata'] = (string) $registry;
     }
     if (isset($array['core_images']) && is_array($array['core_images'])) {
         $registry = new Registry();
         $registry->loadArray($array['core_images']);
         $array['core_images'] = (string) $registry;
     }
     if (isset($array['core_urls']) && is_array($array['core_urls'])) {
         $registry = new Registry();
         $registry->loadArray($array['core_urls']);
         $array['core_urls'] = (string) $registry;
     }
     if (isset($array['core_body']) && is_array($array['core_body'])) {
         $registry = new Registry();
         $registry->loadArray($array['core_body']);
         $array['core_body'] = (string) $registry;
     }
     return parent::bind($array, $ignore);
 }
 /**
  * Stores a FamilyUnit
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return    boolean    True on success, false on failure.
  *
  * @since    1.7.0
  */
 public function store($updateNulls = false)
 {
     // Transform the params field
     if (is_array($this->params)) {
         $registry = new Registry();
         $registry->loadArray($this->params);
         $this->params = (string) $registry;
     }
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     if ($this->id) {
         // Existing item
         $this->modified = $date->toSql();
         $this->modified_by = $user->get('id');
     } else {
         // New newsfeed. A feed created and created_by field can be set by the user,
         // so we don't touch either of these if they are set.
         if (!intval($this->created)) {
             $this->created = $date->toSql();
         }
         if (empty($this->created_by)) {
             $this->created_by = $user->get('id');
         }
     }
     // Attempt to store the data.
     return parent::store($updateNulls);
 }
Example #5
0
 /**
  * Method to bind an associative array or object to the JTable instance.  This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  An optional array or space separated list of properties
  *                          to ignore while binding. [optional]
  *
  * @return  mixed  Null if operation was satisfactory, otherwise returns an error string
  *
  * @since   2.5
  */
 public function bind($array, $ignore = '')
 {
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     return parent::bind($array, $ignore);
 }
Example #6
0
 /**
  * Method to bind an associative array or object to the JTable instance.This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   mixed  $src     An associative array or object to bind to the JTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function bind($src, $ignore = array())
 {
     if (isset($src['params']) && is_array($src['params'])) {
         $registry = new Registry();
         $registry->loadArray($src['params']);
         $src['params'] = (string) $registry;
     }
     parent::bind($src, $ignore);
     return true;
 }
Example #7
0
 /**
  * prepareExecute
  *
  * @return  void
  */
 protected function prepareExecute()
 {
     parent::prepareExecute();
     $this->app->setUserState("com_userxtd.edit.field.data", $this->input->getVar('jform'));
     $attrs = $this->app->getUserState("com_userxtd.edit.field.attrs", array());
     $postAttrs = $this->input->getVar('attrs', array());
     $attrs = new Registry($attrs);
     $attrs->loadArray($postAttrs);
     $this->app->setUserState("com_userxtd.edit.field.attrs", $attrs->toArray());
 }
Example #8
0
 /**
  * Overloaded bind function to pre-process the params.
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  null|string	null if operation was satisfactory, otherwise returns an error
  *
  * @since   1.6
  */
 public function bind($array, $ignore = '')
 {
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     // Verify that the default style is not unset
     if ($array['home'] == '0' && $this->home == '1') {
         $this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_UNSET_DEFAULT_STYLE'));
         return false;
     }
     return parent::bind($array, $ignore);
 }
Example #9
0
 /**
  * Overloaded bind function
  *
  * @param   array  $array   hash named array
  * @param   array  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  null|string	 null is operation was satisfactory, otherwise returns an error
  */
 public function bind($array, $ignore = array())
 {
     // Bind the rules.
     if (isset($array['rules']) && is_array($array['rules'])) {
         $rules = new JAccessRules($array['rules']);
         $this->setRules($rules);
     }
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     return parent::bind($array, $ignore);
 }
Example #10
0
 /**
  * Method to bind an associative array or object to the JTable instance.This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   mixed  $src     An associative array or object to bind to the JTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function bind($src, $ignore = array())
 {
     // Bind the rules.
     if (isset($src['rules']) && is_array($src['rules'])) {
         $rules = new JAccessRules($src['rules']);
         $this->setRules($rules);
     }
     // Covert the params to a json object if its set as an array
     if (isset($src['params']) && is_array($src['params'])) {
         $registry = new Registry();
         $registry->loadArray($src['params']);
         $src['params'] = (string) $registry;
     }
     return parent::bind($src, $ignore);
 }
Example #11
0
 /**
  * Stores a proveedor.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  boolean  True on success, false on failure.
  *
  * @since   1.6
  */
 public function store($updateNulls = false)
 {
     // Transform the params field
     if (is_array($this->params)) {
         $registry = new Registry();
         $registry->loadArray($this->params);
         $this->params = (string) $registry;
     }
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     $this->modified = $date->toSql();
     if ($this->id) {
         // Existing item
         $this->modified_by = $user->get('id');
     } else {
         // New proveedor. A proveedor created and created_by field can be set by the user,
         // so we don't touch either of these if they are set.
         if (!(int) $this->created) {
             $this->created = $date->toSql();
         }
         if (empty($this->created_by)) {
             $this->created_by = $user->get('id');
         }
     }
     // Set publish_up to null date if not set
     if (!$this->publish_up) {
         $this->publish_up = $this->_db->getNullDate();
     }
     // Set publish_down to null date if not set
     if (!$this->publish_down) {
         $this->publish_down = $this->_db->getNullDate();
     }
     // Set xreference to empty string if not set
     if (!$this->xreference) {
         $this->xreference = '';
     }
     // Store utf8 email as punycode
     $this->email_to = JStringPunycode::emailToPunycode($this->email_to);
     // Convert IDN urls to punycode
     $this->webpage = JStringPunycode::urlToPunycode($this->webpage);
     // Verify that the alias is unique
     $table = JTable::getInstance('Proveedor', 'ProveedorTable');
     if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) {
         $this->setError(JText::_('COM_PROVEEDOR_ERROR_UNIQUE_ALIAS'));
         return false;
     }
     return parent::store($updateNulls);
 }
Example #12
0
 /**
  * Method to bind an associative array or object to the JTable instance.This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   mixed  $src     An associative array or object to bind to the JTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function bind($src, $ignore = array())
 {
     if (isset($src['params']) && is_array($src['params'])) {
         $registry = new Registry();
         $registry->loadArray($src['params']);
         $src['params'] = (string) $registry;
     }
     // Needed for form edit view where we see the database table anme and connection id
     if (array_key_exists('db_table_name', $src)) {
         $this->db_table_name = $src['db_table_name'];
     }
     if (array_key_exists('connection_id', $src)) {
         $this->connection_id = $src['connection_id'];
     }
     return parent::bind($src, $ignore);
 }
Example #13
0
 /**
  * Overloaded bind function
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  mixed  Null if operation was satisfactory, otherwise returns an error
  *
  * @see     JTable::bind()
  * @since   11.1
  */
 public function bind($array, $ignore = '')
 {
     // Verify that the default home menu is not unset
     if ($this->home == '1' && $this->language == '*' && $array['home'] == '0') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT_DEFAULT'));
         return false;
     }
     // Verify that the default home menu set to "all" languages" is not unset
     if ($this->home == '1' && $this->language == '*' && $array['language'] != '*') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT'));
         return false;
     }
     // Verify that the default home menu is not unpublished
     if ($this->home == '1' && $this->language == '*' && $array['published'] != '1') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNPUBLISH_DEFAULT_HOME'));
         return false;
     }
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     return parent::bind($array, $ignore);
 }
Example #14
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     $filter = JFilterInput::getInstance();
     if (isset($data['metadata']) && isset($data['metadata']['author'])) {
         $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
     }
     if (isset($data['created_by_alias'])) {
         $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
     }
     if (isset($data['images']) && is_array($data['images'])) {
         $registry = new Registry();
         $registry->loadArray($data['images']);
         $data['images'] = (string) $registry;
     }
     if (isset($data['urls']) && is_array($data['urls'])) {
         $check = $input->post->get('jform', array(), 'array');
         foreach ($data['urls'] as $i => $url) {
             if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
                 if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) {
                     $data['urls'][$i] = $check['urls'][$i];
                 } else {
                     $data['urls'][$i] = JStringPunycode::urlToPunycode($url);
                 }
             }
         }
         unset($check);
         $registry = new Registry();
         $registry->loadArray($data['urls']);
         $data['urls'] = (string) $registry;
     }
     // Alter the title for save as copy
     if ($input->get('task') == 'save2copy') {
         $origTable = clone $this->getTable();
         $origTable->load($input->getInt('id'));
         if ($data['title'] == $origTable->title) {
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['title'] = $title;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['state'] = 0;
     }
     // Automatic handling of alias for empty fields
     if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
         if ($data['alias'] == null) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['title']);
             }
             $table = JTable::getInstance('Content', 'JTable');
             if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
                 $msg = JText::_('COM_CONTENT_SAVE_WARNING');
             }
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     if (parent::save($data)) {
         if (isset($data['featured'])) {
             $this->featured($this->getState($this->getName() . '.id'), $data['featured']);
         }
         return true;
     }
     return false;
 }
Example #15
0
 /**
  * Overloaded bind function
  *
  * @param   array  $array   Named array to bind
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  mixed  Null if operation was satisfactory, otherwise returns an error
  *
  * @since   1.5
  */
 public function bind($array, $ignore = array())
 {
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         if ((int) $registry->get('width', 0) < 0) {
             $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_WIDTH_LABEL')));
             return false;
         }
         if ((int) $registry->get('height', 0) < 0) {
             $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_HEIGHT_LABEL')));
             return false;
         }
         // Converts the width and height to an absolute numeric value:
         $width = abs((int) $registry->get('width', 0));
         $height = abs((int) $registry->get('height', 0));
         // Sets the width and height to an empty string if = 0
         $registry->set('width', $width ? $width : '');
         $registry->set('height', $height ? $height : '');
         $array['params'] = (string) $registry;
     }
     if (isset($array['imptotal'])) {
         $array['imptotal'] = abs((int) $array['imptotal']);
     }
     return parent::bind($array, $ignore);
 }
Example #16
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     $filter = JFilterInput::getInstance();
     if (isset($data['metadata']) && isset($data['metadata']['author'])) {
         $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
     }
     if (isset($data['created_by_alias'])) {
         $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
     }
     if (isset($data['images']) && is_array($data['images'])) {
         $registry = new Registry();
         $registry->loadArray($data['images']);
         $data['images'] = (string) $registry;
     }
     JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
     // Cast catid to integer for comparison
     $catid = (int) $data['catid'];
     // Check if New Category exists
     if ($catid > 0) {
         $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content');
     }
     // Save New Categoryg
     if ($catid == 0 && $this->canCreateCategory()) {
         $table = array();
         $table['title'] = $data['catid'];
         $table['parent_id'] = 1;
         $table['extension'] = 'com_content';
         $table['language'] = $data['language'];
         $table['published'] = 1;
         // Create new category and get catid back
         $data['catid'] = CategoriesHelper::createCategory($table);
     }
     if (isset($data['urls']) && is_array($data['urls'])) {
         $check = $input->post->get('jform', array(), 'array');
         foreach ($data['urls'] as $i => $url) {
             if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
                 if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) {
                     $data['urls'][$i] = $check['urls'][$i];
                 } else {
                     $data['urls'][$i] = JStringPunycode::urlToPunycode($url);
                 }
             }
         }
         unset($check);
         $registry = new Registry();
         $registry->loadArray($data['urls']);
         $data['urls'] = (string) $registry;
     }
     // Alter the title for save as copy
     if ($input->get('task') == 'save2copy') {
         $origTable = clone $this->getTable();
         $origTable->load($input->getInt('id'));
         if ($data['title'] == $origTable->title) {
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['title'] = $title;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['state'] = 0;
     }
     // Automatic handling of alias for empty fields
     if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
         if ($data['alias'] == null) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['title']);
             }
             $table = JTable::getInstance('Content', 'JTable');
             if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
                 $msg = JText::_('COM_CONTENT_SAVE_WARNING');
             }
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     if (parent::save($data)) {
         if (isset($data['featured'])) {
             $this->featured($this->getState($this->getName() . '.id'), $data['featured']);
         }
         return true;
     }
     return false;
 }
Example #17
0
 /**
  * Method to get a list of teamids.
  *
  * Overriden to inject convert the params fields into an object.
  *
  * @return	mixed	An array of objects on success, false on failure.
  * 
  */
 public function getItems()
 {
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $user_id = $user->get('id');
     $guest = $user->get('guest');
     $groups = $user->getAuthorisedViewLevels();
     // Get the global params
     $global_params = JComponentHelper::getParams('com_knvbapi2', true);
     if ($items = parent::getItems()) {
         // Convert the parameter fields into objects.
         foreach ($items as &$item) {
             $query->clear();
             $teamid_params = new Registry();
             $teamid_params->loadString($item->params);
             // Convert the images field to an array.
             $registry = new Registry();
             $registry->loadString($item->images);
             $item->images = $registry->toArray();
             $registry = null;
             //release memory
             // Convert the urls field to an array.
             $registry = new Registry();
             $registry->loadString($item->urls);
             $item->urls = $registry->toArray();
             $registry = null;
             //release memory
             $item->introdescription = trim($item->intro) != '' ? $item->intro . $item->description : $item->description;
             // Unpack readmore and layout params
             $item->teamid_alternative_readmore = $teamid_params->get('teamid_alternative_readmore');
             $item->layout = $teamid_params->get('layout');
             if (!is_object($this->getState('params'))) {
                 $item->params = $teamid_params;
             } else {
                 $item->params = clone $this->getState('params');
                 // Teamid params override menu item params only if menu param = 'use_teamid'
                 // Otherwise, menu item params control the layout
                 // If menu item is 'use_teamid' and there is no teamid param, use global
                 // create an array of just the params set to 'use_teamid'
                 $menu_params_array = $this->getState('params')->toArray();
                 $teamid_array = array();
                 foreach ($menu_params_array as $key => $value) {
                     if ($value === 'use_teamid') {
                         // if the teamid has a value, use it
                         if ($teamid_params->get($key) != '') {
                             // get the value from the teamid
                             $teamid_array[$key] = $teamid_params->get($key);
                         } else {
                             // otherwise, use the global value
                             $teamid_array[$key] = $global_params->get($key);
                         }
                     }
                 }
                 // merge the selected teamid params
                 if (count($teamid_array) > 0) {
                     $teamid_params = new Registry();
                     $teamid_params->loadArray($teamid_array);
                     $item->params->merge($teamid_params);
                 }
                 // get display date
                 switch ($item->params->get('list_show_teamid_date')) {
                     case 'modified':
                         $item->display_date = $item->modified;
                         break;
                     case 'publish_up':
                         $item->display_date = $item->publish_up;
                         if ($item->publish_up == 0) {
                             $item->display_date = $item->created;
                         }
                         break;
                     case 'created':
                         $item->display_date = $item->created;
                         break;
                     default:
                         $item->display_date = 0;
                         break;
                 }
             }
             // Compute the asset access permissions.
             // Technically guest could edit an teamid, but lets not check that to improve performance a little.
             if (!$guest) {
                 $asset = 'com_knvbapi2.teamid.' . $item->id;
                 // Check general edit permission first.
                 if ($user->authorise('core.edit', $asset)) {
                     $item->params->set('access-edit', true);
                 } else {
                     if (!empty($user_id) and $user->authorise('core.edit.own', $asset)) {
                         // Check for a valid user and that they are the owner.
                         if ($user_id == $item->created_by) {
                             $item->params->set('access-edit', true);
                         }
                     }
                 }
                 if ($user->authorise('core.create', $asset)) {
                     $item->params->set('access-create', true);
                 }
                 if ($user->authorise('core.delete', $asset)) {
                     $item->params->set('access-delete', true);
                 } else {
                     if (!empty($user_id) and $user->authorise('core.delete.own', $asset)) {
                         // Check for a valid user and that they are the owner.
                         if ($user_id == $item->created_by) {
                             $item->params->set('access-delete', true);
                         }
                     }
                 }
             }
             $access = $this->getState('filter.access');
             if ($access) {
                 // If the access filter has been set, we already have only the teamids this user can view.
                 $item->params->set('access-view', true);
             } else {
                 // If no access filter is set, the layout takes some responsibility for display of limited information.
                 $item->params->set('access-view', in_array($item->access, $groups));
             }
             // Get the tags
             $item->tags = new JHelperTags();
             $item->tags->getItemTags('com_knvbapi2.teamid', $item->id);
         }
     }
     return $items;
 }
Example #18
0
 /**
  * Method to get Selectie data.
  *
  * @param	integer	$pk	The id of the selectie.
  *
  * @return	mixed	Menu item data object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     // Get current user for authorisation checks
     $user = JFactory::getUser();
     $pk = !empty($pk) ? $pk : (int) $this->getState('selectie.id');
     // Get the global params
     $global_params = JComponentHelper::getParams('com_knvbapi2', true);
     if ($this->_item === null) {
         $this->_item = array();
     }
     if (!isset($this->_item[$pk])) {
         try {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select($this->getState('item.select', 'a.*'));
             $query->from($db->quoteName('#__knvbapi2_selecties') . ' AS a');
             // Join on user table.
             $query->select($db->quoteName('ua.name') . ' AS created_by_name');
             $query->join('LEFT', $db->quoteName('#__users') . ' AS ua on ' . $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'));
             $query->select($db->quoteName('uam.name') . ' AS modified_by_name');
             $query->join('LEFT', $db->quoteName('#__users') . ' AS uam on ' . $db->quoteName('uam.id') . ' = ' . $db->quoteName('a.modified_by'));
             // Join over the language
             $query->select($db->quoteName('l.title') . ' AS language_title');
             $query->join('LEFT', $db->quoteName('#__languages') . ' AS l ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language'));
             // Filter by language
             if ($this->getState('filter.language')) {
                 $query->where($db->quoteName('a.language') . ' IN (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
             }
             $query->where($db->quoteName('a.id') . ' = ' . (int) $pk);
             // Join on vote rating table
             $query->select('ROUND(' . $db->quoteName('v.rating_sum') . ' / ' . $db->quoteName('v.rating_count') . ', 0) AS rating, ' . $db->quoteName('v.rating_count') . ' as rating_count');
             $query->join('LEFT', $db->quoteName('#__knvbapi2_rating') . ' AS v ON ' . $db->quoteName('a.id') . ' = ' . $db->quoteName('v.content_id') . ' AND ' . $db->quoteName('v.content_type') . ' = ' . $db->quote('selecties'));
             $can_publish = $user->authorise('core.edit.state', 'com_knvbapi2.selectie.' . $pk);
             //  Do not show unless today's date is within the publish up and down dates (or they are empty)
             if (!$can_publish) {
                 $null_date = $db->quote($db->getNullDate());
                 $now_date = $db->quote(JFactory::getDate()->toSQL());
                 $query->where('(' . $db->quoteName('a.publish_up') . ' = ' . $null_date . ' OR ' . $db->quoteName('a.publish_up') . ' <= ' . $now_date . ')');
                 $query->where('(' . $db->quoteName('a.publish_down') . ' = ' . $null_date . ' OR ' . $db->quoteName('a.publish_down') . ' >= ' . $now_date . ')');
             }
             // Filter by published status.
             $published = $this->getState('filter.published');
             $archived = $this->getState('filter.archived');
             if (is_numeric($published) and !$can_publish) {
                 $query->where('(' . $db->quoteName('a.state') . ' = ' . (int) $published . ' OR ' . $db->quoteName('a.state') . ' = ' . (int) $archived . ')');
             }
             $query->select($db->quoteName('vl.title') . ' AS access_title');
             $query->join('LEFT', $db->quoteName('#__viewlevels') . ' AS vl on ' . $db->quoteName('vl.id') . ' = ' . $db->quoteName('a.access'));
             $db->setQuery($query);
             $item = $db->loadObject();
             if (empty($item)) {
                 return JError::raiseError(404, JText::_('COM_KNVBAPI2_SELECTIES_ERROR_ITEM_NOT_FOUND'));
             }
             // Include any manipulation of the data on the record e.g. expand out Registry fields
             // NB The params registry field - if used - is done automatcially in the JAdminModel parent class
             // Convert the images field to an array.
             $registry = new Registry();
             $registry->loadString($item->images);
             $item->images = $registry->toArray();
             $registry = null;
             //release memory
             // Convert the urls field to an array.
             $registry = new Registry();
             $registry->loadString($item->urls);
             $item->urls = $registry->toArray();
             $registry = null;
             //release memory
             $item->tags = new JHelperTags();
             $item->tags->getItemTags('com_knvbapi2.selectie', $item->id);
             // Check for published state if filter set.
             if ((is_numeric($published) or is_numeric($archived)) and ($item->state != $published and $item->state != $archived)) {
                 return JError::raiseError(404, JText::_('COM_KNVBAPI2_SELECTIES_ERROR_ITEM_NOT_FOUND'));
             }
             $item->introdescription = trim($item->intro) != '' ? $item->intro . $item->description : $item->description;
             // Convert parameter fields to objects.
             $selectie_params = new Registry();
             $selectie_params->loadString($item->params);
             // Unpack readmore and layout params
             $item->selectie_alternative_readmore = $selectie_params->get('selectie_alternative_readmore');
             $item->layout = $selectie_params->get('layout');
             $item->params = clone $this->getState('params');
             // Selectie params override menu item params only if menu param = 'use_selectie'
             // Otherwise, menu item params control the layout
             // If menu item is 'use_selectie' and there is no selectie param, use global
             // create an array of just the params set to 'use_selectie'
             $menu_params_array = $this->getState('params')->toArray();
             $selectie_array = array();
             foreach ($menu_params_array as $key => $value) {
                 if ($value === 'use_selectie') {
                     // if the selectie has a value, use it
                     if ($selectie_params->get($key) != '') {
                         // get the value from the selectie
                         $selectie_array[$key] = $selectie_params->get($key);
                     } else {
                         // otherwise, use the global value
                         $selectie_array[$key] = $global_params->get($key);
                     }
                 }
             }
             // merge the selected selectie params
             if (count($selectie_array) > 0) {
                 $selectie_params = new Registry();
                 $selectie_params->loadArray($selectie_array);
                 $item->params->merge($selectie_params);
             }
             // Compute selected asset permissions.
             // Technically guest could edit an selectie, but lets not check that to improve performance a little.
             if (!$user->get('guest')) {
                 $user_id = $user->get('id');
                 $asset = 'com_knvbapi2.selectie.' . $item->id;
                 // Check general edit permission first.
                 if ($user->authorise('core.edit', $asset)) {
                     $item->params->set('access-edit', true);
                 } else {
                     if (!empty($user_id) and $user->authorise('core.edit.own', $asset)) {
                         // Check for a valid user and that they are the owner.
                         if ($user_id == $item->created_by) {
                             $item->params->set('access-edit', true);
                             // If owner allow them to edit state in front end
                             $item->params->set('access-change', true);
                         }
                     }
                 }
                 if ($user->authorise('core.create', $asset)) {
                     $item->params->set('access-create', true);
                 }
                 if ($user->authorise('core.delete', $asset)) {
                     $item->params->set('access-delete', true);
                 } else {
                     if (!empty($user_id) and $user->authorise('core.delete.own', $asset)) {
                         // Check for a valid user and that they are the owner.
                         if ($user_id == $item->created_by) {
                             $item->params->set('access-delete', true);
                         }
                     }
                 }
                 // Check edit state permission.
                 if ($user->authorise('core.edit.state', $asset)) {
                     $item->params->set('access-change', true);
                 }
             }
             // Compute view access permissions.
             if ($access = $this->getState('filter.access')) {
                 // If the access filter has been set, we already know this user can view.
                 $item->params->set('access-view', true);
             } else {
                 // If no access filter is set, the layout takes some responsibility for display of limited information.
                 $groups = $user->getAuthorisedViewLevels();
                 $item->params->set('access-view', in_array($item->access, $groups));
             }
             $this->_item[$pk] = $item;
         } catch (Exception $e) {
             if ($e->getCode() == 404) {
                 // Need to go thru the error handler to allow Redirect to work.
                 JError::raiseError(404, $e->getMessage());
             } else {
                 $this->setError($e);
                 $this->_item[$pk] = false;
             }
         }
     }
     return $this->_item[$pk];
 }
Example #19
0
 /**
  * @param $uid
  * @param $itemid
  *
  * @return int
  */
 public function toggleItem($uid, $itemid)
 {
     $sitemap = $this->getItem();
     $items = $this->getItems();
     $extensions = $this->getExtensions();
     $displayer = new XmapDisplayerHtml($sitemap, $items, $extensions);
     $excludedItems = $displayer->getExcludedItems();
     if (isset($excludedItems[$itemid])) {
         $excludedItems[$itemid] = (array) $excludedItems[$itemid];
     }
     if (!$displayer->isExcluded($itemid, $uid)) {
         $excludedItems[$itemid][] = $uid;
         $state = 0;
     } else {
         if (is_array($excludedItems[$itemid]) && count($excludedItems[$itemid])) {
             // TODO refactor, create_function is bad
             $excludedItems[$itemid] = array_filter($excludedItems[$itemid], create_function('$var', 'return ($var != \'' . $uid . '\');'));
         } else {
             unset($excludedItems[$itemid]);
         }
         $state = 1;
     }
     $registry = new Registry();
     $registry->loadArray($excludedItems);
     $str = $registry->toString();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->update('#__xmap_sitemap AS s')->set('s.excluded_items = ' . $db->quote($str))->where('s.id = ' . $db->quote($sitemap->id));
     $db->setQuery($query);
     $db->execute();
     return $state;
 }
Example #20
0
 /**
  * Method to get a list of articles.
  *
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return  mixed  An array of objects on success, false on failure.
  *
  * @since   1.6
  */
 public function getItems()
 {
     $items = parent::getItems();
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $guest = $user->get('guest');
     $groups = $user->getAuthorisedViewLevels();
     $input = JFactory::getApplication()->input;
     // Get the global params
     $globalParams = JComponentHelper::getParams('com_content', true);
     // Convert the parameter fields into objects.
     foreach ($items as &$item) {
         $articleParams = new Registry();
         $articleParams->loadString($item->attribs);
         // Unpack readmore and layout params
         $item->alternative_readmore = $articleParams->get('alternative_readmore');
         $item->layout = $articleParams->get('layout');
         $item->params = clone $this->getState('params');
         /*For blogs, article params override menu item params only if menu param = 'use_article'
         		Otherwise, menu item params control the layout
         		If menu item is 'use_article' and there is no article param, use global*/
         if ($input->getString('layout') == 'blog' || $input->getString('view') == 'featured' || $this->getState('params')->get('layout_type') == 'blog') {
             // Create an array of just the params set to 'use_article'
             $menuParamsArray = $this->getState('params')->toArray();
             $articleArray = array();
             foreach ($menuParamsArray as $key => $value) {
                 if ($value === 'use_article') {
                     // If the article has a value, use it
                     if ($articleParams->get($key) != '') {
                         // Get the value from the article
                         $articleArray[$key] = $articleParams->get($key);
                     } else {
                         // Otherwise, use the global value
                         $articleArray[$key] = $globalParams->get($key);
                     }
                 }
             }
             // Merge the selected article params
             if (count($articleArray) > 0) {
                 $articleParams = new Registry();
                 $articleParams->loadArray($articleArray);
                 $item->params->merge($articleParams);
             }
         } else {
             // For non-blog layouts, merge all of the article params
             $item->params->merge($articleParams);
         }
         // Get display date
         switch ($item->params->get('list_show_date')) {
             case 'modified':
                 $item->displayDate = $item->modified;
                 break;
             case 'published':
                 $item->displayDate = $item->publish_up == 0 ? $item->created : $item->publish_up;
                 break;
             default:
             case 'created':
                 $item->displayDate = $item->created;
                 break;
         }
         // Compute the asset access permissions.
         // Technically guest could edit an article, but lets not check that to improve performance a little.
         if (!$guest) {
             $asset = 'com_content.article.' . $item->id;
             // Check general edit permission first.
             if ($user->authorise('core.edit', $asset)) {
                 $item->params->set('access-edit', true);
             } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
                 // Check for a valid user and that they are the owner.
                 if ($userId == $item->created_by) {
                     $item->params->set('access-edit', true);
                 }
             }
         }
         $access = $this->getState('filter.access');
         if ($access) {
             // If the access filter has been set, we already have only the articles this user can view.
             $item->params->set('access-view', true);
         } else {
             // If no access filter is set, the layout takes some responsibility for display of limited information.
             if ($item->catid == 0 || $item->category_access === null) {
                 $item->params->set('access-view', in_array($item->access, $groups));
             } else {
                 $item->params->set('access-view', in_array($item->access, $groups) && in_array($item->category_access, $groups));
             }
         }
         // Get the tags
         if ($item->params->get('show_tags')) {
             $item->tags = new JHelperTags();
             $item->tags->getItemTags('com_content.article', $item->id);
         }
     }
     return $items;
 }
Example #21
0
 /**
  * Test the registry set for unassociative arrays
  *
  * @return  void
  *
  * @since   1.4.0
  */
 public function testUnassocArrays()
 {
     $a = new Registry();
     $a->loadArray(array('assoc' => array('foo' => 'bar'), 'unassoc' => array('baz', 'baz2', 'baz3'), 'mixed' => array('var', 'var2', 'key' => 'var3')));
     $a->set('assoc.foo2', 'bar2');
     $this->assertEquals('bar2', $a->get('assoc.foo2'));
     $a->set('mixed.key2', 'var4');
     $this->assertEquals('var4', $a->get('mixed.key2'));
     $a->set('mixed.2', 'var5');
     $this->assertEquals('var5', $a->get('mixed.2'));
     $this->assertEquals('var2', $a->get('mixed.1'));
     $a->set('unassoc.3', 'baz4');
     $this->assertEquals('baz4', $a->get('unassoc.3'));
     $this->assertTrue(is_array($a->get('unassoc')), 'Un-associative array should remain after write');
 }
Example #22
0
 /**
  * Load the editor
  *
  * @param   array  $config  Associative array of editor config paramaters
  *
  * @return  mixed
  *
  * @since   1.5
  */
 protected function _loadEditor($config = array())
 {
     // Check whether editor is already loaded
     if (!is_null($this->_editor)) {
         return;
     }
     // Build the path to the needed editor plugin
     $name = JFilterInput::getInstance()->clean($this->_name, 'cmd');
     $path = JPATH_PLUGINS . '/editors/' . $name . '/' . $name . '.php';
     if (!is_file($path)) {
         JLog::add(JText::_('JLIB_HTML_EDITOR_CANNOT_LOAD'), JLog::WARNING, 'jerror');
         return false;
     }
     // Require plugin file
     require_once $path;
     // Get the plugin
     $plugin = JPluginHelper::getPlugin('editors', $this->_name);
     // If no plugin is published we get an empty array and there not so much to do with it
     if (empty($plugin)) {
         return false;
     }
     $params = new Registry();
     $params->loadString($plugin->params);
     $params->loadArray($config);
     $plugin->params = $params;
     // Build editor plugin classname
     $name = 'PlgEditor' . $this->_name;
     if ($this->_editor = new $name($this, (array) $plugin)) {
         // Load plugin parameters
         $this->initialise();
         JPluginHelper::importPlugin('editors-xtd');
     }
 }
    /**
     * Test the Joomla\Registry\Registry::merge method.
     *
     * @return  void
     *
     * @covers  Joomla\Registry\Registry::merge
     * @since   1.0
     */
    public function testMerge()
    {
        $array1 = array('foo' => 'bar', 'hoo' => 'hum', 'dum' => array('dee' => 'dum'));
        $array2 = array('foo' => 'soap', 'dum' => 'huh');
        $registry1 = new Registry();
        $registry1->loadArray($array1);
        $registry2 = new Registry();
        $registry2->loadArray($array2);
        $registry1->merge($registry2);
        // Test getting a known value.
        $this->assertThat($registry1->get('foo'), $this->equalTo('soap'), 'Line: ' . __LINE__ . '.');
        $this->assertThat($registry1->get('dum'), $this->equalTo('huh'), 'Line: ' . __LINE__ . '.');
        // Test merge with zero and blank value
        $json1 = '{
			"param1":1,
			"param2":"value2"
		}';
        $json2 = '{
			"param1":2,
			"param2":"",
			"param3":0,
			"param4":-1,
			"param5":1
		}';
        $a = new Registry($json1);
        $b = new Registry();
        $b->loadString($json2, 'JSON');
        $result = $a->merge($b);
        // New param with zero value should show in merged registry
        $this->assertEquals(2, $a->get('param1'), '$b value should override $a value');
        $this->assertEquals('value2', $a->get('param2'), '$a value should override blank $b value');
        $this->assertEquals(0, $a->get('param3'), '$b value of 0 should override $a value');
        $this->assertEquals(-1, $a->get('param4'), '$b value of -1 should override $a value');
        $this->assertEquals(1, $a->get('param5'), '$b value of 1 should override $a value');
        // Test recursive merge
        $registry = new Registry();
        $object1 = '{
			"foo" : "foo value",
			"bar" : {
				"bar1" : "bar value 1",
				"bar2" : "bar value 2"
			}
		}';
        $object2 = '{
			"foo" : "foo value",
			"bar" : {
				"bar2" : "new bar value 2"
			}
		}';
        $registry1 = new Registry(json_decode($object1));
        $registry2 = new Registry(json_decode($object2));
        $registry1->merge($registry2, true);
        $this->assertEquals($registry1->get('bar.bar2'), 'new bar value 2', 'Line: ' . __LINE__ . '. bar.bar2 shuould be override.');
        $this->assertEquals($registry1->get('bar.bar1'), 'bar value 1', 'Line: ' . __LINE__ . '. bar.bar1 should not be overrided.');
        // Chicking we merge a non Registry object will return error.
        $a = new Registry();
        $b = new stdClass();
        try {
            $a->merge($b);
        } catch (Exception $e) {
            $this->assertInstanceOf('PHPUnit_Framework_Error', $e, 'Line: ' . __LINE__ . '. Attempt to merge non Registry should return Error');
        }
    }
Example #24
0
 /**
  * Method to unset the root_user value from configuration data.
  *
  * This method will load the global configuration data straight from
  * JConfig and remove the root_user value for security, then save the configuration.
  *
  * @return	boolean  True on success, false on failure.
  *
  * @since	1.6
  */
 public function removeroot()
 {
     // Get the previous configuration.
     $prev = new JConfig();
     $prev = JArrayHelper::fromObject($prev);
     // Create the new configuration object, and unset the root_user property
     $config = new Registry('config');
     unset($prev['root_user']);
     $config->loadArray($prev);
     // Write the configuration file.
     return $this->writeConfigFile($config);
 }
Example #25
0
 /**
  * Overloaded bind function
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  An optional array or space separated list of properties
  *                          to ignore while binding.
  *
  * @return  mixed  Null if operation was satisfactory, otherwise returns an error string
  *
  * @see     JTable::bind()
  * @since   11.1
  */
 public function bind($array, $ignore = '')
 {
     // Search for the {readmore} tag and split the text up accordingly.
     if (isset($array['articletext'])) {
         $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
         $tagPos = preg_match($pattern, $array['articletext']);
         if ($tagPos == 0) {
             $this->introtext = $array['articletext'];
             $this->fulltext = '';
         } else {
             list($this->introtext, $this->fulltext) = preg_split($pattern, $array['articletext'], 2);
         }
     }
     if (isset($array['attribs']) && is_array($array['attribs'])) {
         $registry = new Registry();
         $registry->loadArray($array['attribs']);
         $array['attribs'] = (string) $registry;
     }
     if (isset($array['metadata']) && is_array($array['metadata'])) {
         $registry = new Registry();
         $registry->loadArray($array['metadata']);
         $array['metadata'] = (string) $registry;
     }
     // Bind the rules.
     if (isset($array['rules']) && is_array($array['rules'])) {
         $rules = new JAccessRules($array['rules']);
         $this->setRules($rules);
     }
     return parent::bind($array, $ignore);
 }
Example #26
0
 /**
  * Stores a Selectie
  *
  * @param	boolean	$update_nulls	True to update fields even if they are null.
  * 
  * @return	boolean	$result			True on success, false on failure.
  * 
  */
 public function store($update_nulls = false)
 {
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     if (empty($this->id)) {
         // New Selectie. A created and created_by field can be set by the user,
         // so we don't touch either of these if they are set.
         if (!intval($this->created)) {
             $this->created = $date->toSQL();
         }
         if (empty($this->created_by)) {
             $this->created_by = $user->get('id');
         }
     }
     // Existing item
     $this->modified = $date->toSQL();
     $this->modified_by = $user->get('id');
     // Set publish_up to null date if not set
     if (!$this->publish_up) {
         $this->publish_up = $this->_db->getNullDate();
     }
     // Set publish_down to null date if not set
     if (!$this->publish_down) {
         $this->publish_down = $this->_db->getNullDate();
     }
     // Set xreference to empty string if not set
     if (!$this->xreference) {
         $this->xreference = '';
     }
     if (isset($this->images) and is_array($this->images)) {
         $registry = new Registry();
         $registry->loadArray($this->images);
         $this->images = (string) $registry;
         $registry = null;
         //release memory
     }
     if (isset($this->urls) and is_array($this->urls)) {
         $registry = new Registry();
         $registry->loadArray($this->urls);
         $this->urls = (string) $registry;
         $registry = null;
         //release memory
     }
     if (isset($this->params) and is_array($this->params)) {
         $registry = new Registry();
         $registry->loadArray($this->params);
         $this->params = (string) $registry;
         $registry = null;
         //release memory
     }
     // Attempt to store the data.
     return parent::store($update_nulls);
 }
Example #27
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     $filter = JFilterInput::getInstance();
     if (isset($data['metadata']) && isset($data['metadata']['author'])) {
         $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
     }
     if (isset($data['created_by_alias'])) {
         $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
     }
     if (isset($data['images']) && is_array($data['images'])) {
         $registry = new Registry();
         $registry->loadArray($data['images']);
         $data['images'] = (string) $registry;
     }
     if (isset($data['urls']) && is_array($data['urls'])) {
         foreach ($data['urls'] as $i => $url) {
             if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
                 $data['urls'][$i] = JStringPunycode::urlToPunycode($url);
             }
         }
         $registry = new Registry();
         $registry->loadArray($data['urls']);
         $data['urls'] = (string) $registry;
     }
     // Alter the title for save as copy
     if ($input->get('task') == 'save2copy') {
         $origTable = clone $this->getTable();
         $origTable->load($input->getInt('id'));
         if ($data['title'] == $origTable->title) {
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['title'] = $title;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['state'] = 0;
     }
     // Automatic handling of alias for empty fields
     if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
         if ($data['alias'] == null) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['title']);
             }
             $table = JTable::getInstance('Content', 'JTable');
             if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
                 $msg = JText::_('COM_CONTENT_SAVE_WARNING');
             }
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     if (parent::save($data)) {
         if (isset($data['featured'])) {
             $this->featured($this->getState($this->getName() . '.id'), $data['featured']);
         }
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $id = (int) $this->getState($this->getName() . '.id');
             $item = $this->getItem($id);
             // Adding self to the association
             $associations = $data['associations'];
             foreach ($associations as $tag => $id) {
                 if (empty($id)) {
                     unset($associations[$tag]);
                 }
             }
             // Detecting all item menus
             $all_language = $item->language == '*';
             if ($all_language && !empty($associations)) {
                 JError::raiseNotice(403, JText::_('COM_CONTENT_ERROR_ALL_LANGUAGE_ASSOCIATED'));
             }
             $associations[$item->language] = $item->id;
             // Deleting old association for these items
             $db = JFactory::getDbo();
             $query = $db->getQuery(true)->delete('#__associations')->where('context=' . $db->quote('com_content.item'))->where('id IN (' . implode(',', $associations) . ')');
             $db->setQuery($query);
             $db->execute();
             if ($error = $db->getErrorMsg()) {
                 $this->setError($error);
                 return false;
             }
             if (!$all_language && count($associations)) {
                 // Adding new association for these items
                 $key = md5(json_encode($associations));
                 $query->clear()->insert('#__associations');
                 foreach ($associations as $id) {
                     $query->values($id . ',' . $db->quote('com_content.item') . ',' . $db->quote($key));
                 }
                 $db->setQuery($query);
                 $db->execute();
                 if ($error = $db->getErrorMsg()) {
                     $this->setError($error);
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
Example #28
0
 /**
  * Method to bind an associative array of data to a user object
  *
  * @param   array  &$array  The associative array to bind to the object
  *
  * @return  boolean  True on success
  *
  * @since   11.1
  */
 public function bind(&$array)
 {
     // Let's check to see if the user is new or not
     if (empty($this->id)) {
         // Check the password and create the crypted password
         if (empty($array['password'])) {
             $array['password'] = $this->userHelper->genRandomPassword();
             $array['password2'] = $array['password'];
         }
         // Not all controllers check the password, although they should.
         // Hence this code is required:
         if (isset($array['password2']) && $array['password'] != $array['password2']) {
             JFactory::getApplication()->enqueueMessage(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'), 'error');
             return false;
         }
         $this->password_clear = ArrayHelper::getValue($array, 'password', '', 'string');
         $array['password'] = $this->userHelper->hashPassword($array['password']);
         // Set the registration timestamp
         $this->set('registerDate', JFactory::getDate()->toSql());
         // Check that username is not greater than 150 characters
         $username = $this->get('username');
         if (strlen($username) > 150) {
             $username = substr($username, 0, 150);
             $this->set('username', $username);
         }
     } else {
         // Updating an existing user
         if (!empty($array['password'])) {
             if ($array['password'] != $array['password2']) {
                 $this->setError(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
                 return false;
             }
             $this->password_clear = ArrayHelper::getValue($array, 'password', '', 'string');
             // Check if the user is reusing the current password if required to reset their password
             if ($this->requireReset == 1 && $this->userHelper->verifyPassword($this->password_clear, $this->password)) {
                 $this->setError(JText::_('JLIB_USER_ERROR_CANNOT_REUSE_PASSWORD'));
                 return false;
             }
             $array['password'] = $this->userHelper->hashPassword($array['password']);
             // Reset the change password flag
             $array['requireReset'] = 0;
         } else {
             $array['password'] = $this->password;
         }
     }
     if (array_key_exists('params', $array)) {
         $this->_params->loadArray($array['params']);
         if (is_array($array['params'])) {
             $params = (string) $this->_params;
         } else {
             $params = $array['params'];
         }
         $this->params = $params;
     }
     // Bind the array
     if (!$this->setProperties($array)) {
         $this->setError(JText::_('JLIB_USER_ERROR_BIND_ARRAY'));
         return false;
     }
     // Make sure its an integer
     $this->id = (int) $this->id;
     return true;
 }
Example #29
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success, False on error.
  *
  */
 public function save($data)
 {
     // Include the knvbapi plugins for the onSave events.
     JPluginHelper::importPlugin('knvbapi2');
     $input = JFactory::getApplication()->input;
     $filter = JFilterInput::getInstance();
     if (isset($data['created_by_alias'])) {
         $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
     }
     if (isset($data['images']) and is_array($data['images'])) {
         $registry = new Registry();
         $registry->loadArray($data['images']);
         $data['images'] = (string) $registry;
         $registry = null;
         //release memory
     }
     if (isset($data['urls']) and is_array($data['urls'])) {
         foreach ($data['urls'] as $i => $url) {
             if ($url != false and ($i == 'urla' or $i == 'urlb' or $i == 'urlc')) {
                 $data['urls'][$i] = JStringPunycode::urlToPunycode($url);
             }
         }
         $registry = new Registry();
         $registry->loadArray($data['urls']);
         $data['urls'] = (string) $registry;
         $registry = null;
         //release memory
     }
     // Alter the name and alias for save as copy
     if ($input->get('task') == 'save2copy') {
         $data['name'] = $this->generateUniqueName($data);
         $data['alias'] = $this->generateUniqueAlias($data);
         $data['state'] = 0;
     }
     if (parent::save($data)) {
         if (isset($data['featured'])) {
             $this->featured($this->getState($this->getName() . '.id'), $data['featured']);
         }
         $assoc = JLanguageAssociations::isEnabled();
         if ($assoc) {
             $id = (int) $this->getState($this->getName() . '.id');
             $item = $this->getItem($id);
             // Adding self to the association
             $associations = $data['associations'];
             foreach ($associations as $tag => $id) {
                 if (empty($id)) {
                     unset($associations[$tag]);
                 }
             }
             // Detecting all item menus
             $all_language = $item->language == '*';
             if ($all_language and !empty($associations)) {
                 JError::raiseNotice(403, JText::_('COM_KNVBAPI2_ERROR_ALL_LANGUAGE_ASSOCIATED'));
             }
             $associations[$item->language] = $item->id;
             try {
                 // Deleting old association for these items
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->delete($db->quoteName('#__associations'));
                 $query->where('context=' . $db->quote('com_knvbapi2.teamnaam.item'));
                 $query->where($db->quoteName('id') . ' IN (' . implode(',', $associations) . ')');
                 $db->setQuery($query);
                 $db->execute();
             } catch (RuntimeException $e) {
                 $this->setError($e->getMessage());
                 return false;
             }
             if (!$all_language and count($associations)) {
                 // Adding new association for these items
                 $key = md5(json_encode($associations));
                 $query->clear();
                 $query->insert($db->quoteName('#__associations'));
                 foreach ($associations as $id) {
                     $query->values($id . ',' . $db->quote('com_knvbapi2.teamnaam.item') . ',' . $db->quote($key));
                 }
                 try {
                     $db->setQuery($query);
                     $db->execute();
                 } catch (RuntimeException $e) {
                     $this->setError($e->getMessage());
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
Example #30
0
 /**
  * Function that allows child controller access to model data after the data has been saved.
  *
  * @param   JModelLegacy  $model      The data model object.
  * @param   array         $validData  The validated data.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function postSaveHook(JModelLegacy $model, $validData = array())
 {
     $item = $model->getItem();
     if (isset($item->params) && is_array($item->params)) {
         $registry = new Registry();
         $registry->loadArray($item->params);
         $item->params = (string) $registry;
     }
     if (isset($item->metadata) && is_array($item->metadata)) {
         $registry = new Registry();
         $registry->loadArray($item->metadata);
         $item->metadata = (string) $registry;
     }
 }